﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BAL;
namespace QuanLyTiemNET_DEV_LINQ
{
    public partial class XtraFormThemDichVu : DevExpress.XtraEditors.XtraForm
    {
        public XtraFormThemDichVu()
        {
            InitializeComponent();
        }

        private void XtraFormThemDichVu_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = BAL_DICHVU.LayThongTinDV();
            comboBox1.DisplayMember = "TenDV";
            comboBox1.ValueMember = "MaDV";
            txtDonGia.Text = BAL_DICHVU.LayGiaDichVu(comboBox1.SelectedValue.ToString()).ToString();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtDonGia.Text = BAL_DICHVU.LayGiaDichVu(comboBox1.SelectedValue.ToString()).ToString();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            comboBox1.ResetText();
            txtDonGia.Text = "0";
            txtSoLuong.ResetText();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {

            string err = null;
            try
            {
                if (txtSoLuong.Text.Count()!=0)
                {
                    if (BAL_CHITIETSUDUNGDV.ThemCTSDDV(ref err, comboBox1.SelectedValue.ToString(), BAL_CHITIETTHUEMAY.LayMaPhieu(FrmPhongMay.but.Name), int.Parse(txtSoLuong.Text), float.Parse(txtDonGia.Text)))
                    {
                        MessageBox.Show("Thêm dịch vụ sử dụng thành công!!!");
                        comboBox1.ResetText();
                        txtDonGia.Text = "0";
                        txtSoLuong.ResetText();
                    }
                    else
                    {
                        MessageBox.Show("Lỗi: " + err);
                        comboBox1.ResetText();
                        txtDonGia.Text = "0";
                        txtSoLuong.ResetText();
                    }
                }
                else
                    MessageBox.Show("Bạn phải nhập số lượng để tiến hành thêm dịch vụ sử dụng!!!!");
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
                comboBox1.ResetText();
                txtDonGia.Text = "0";
                txtSoLuong.ResetText();
            }
        }
    }
}